import 'package:flutter/material.dart';
import 'package:ninetyfour/l10n/app_localizations.dart';
import '../controller/webview.dart';
import '../../manger/global_config.dart';
class ProtocolDialog extends StatelessWidget {
  final VoidCallback onCancel;
  final VoidCallback onSure;
  const ProtocolDialog({super.key, required this.onCancel, required this.onSure});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(15),
      ),
      child: Container(
        height: 160,
        padding: const EdgeInsets.all(20),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
             Expanded(
            child: GestureDetector(
              onTap: () {
                // 处理协议文本点击事件
              },
              child: RichText(
                text: TextSpan(
                  style: const TextStyle(
                    fontSize: 15,
                    color: Color(0xFF999999),
                  ),
                  children: [
                    TextSpan(text: AppLocalizations.of(context)!.iHaveReadAndAgree),
                    WidgetSpan(
                      alignment: PlaceholderAlignment.middle,
                      child: GestureDetector(
                        onTap: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => WebViewPage(
                                title: AppLocalizations.of(context)!.news,
                                url: UrlConfig.payProtocalURL(context),
                              ),
                            ),
                          );
                        },
                        child: Text(
                          AppLocalizations.of(context)!.userAgreement,
                          style: const TextStyle(fontSize: 15,color: Color(0xFF4187FD)),
                        ),
                      ),
                    ),
                    if (!isChineseLocale())
                    TextSpan(text: " and"),
                    WidgetSpan(
                      alignment: PlaceholderAlignment.middle,
                      child: GestureDetector(
                        onTap: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => WebViewPage(
                                title: AppLocalizations.of(context)!.news,
                                url: UrlConfig.privacyPolicyURL(context),
                              ),
                            ),
                          );      
                        },
                        child: Text(
                          AppLocalizations.of(context)!.privacyAgreement,
                          style: const TextStyle(fontSize: 15,color: Color(0xFF4187FD)),
                        ),
                      ),
                    ),
                    if (isChineseLocale())
                    WidgetSpan(
                      alignment: PlaceholderAlignment.middle,
                      child: GestureDetector(
                        onTap: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => WebViewPage(
                                title: AppLocalizations.of(context)!.news,
                                url: UrlConfig.mianURL(context),
                              ),
                            ),
                          );                          
                        },
                        child: Text(
                          AppLocalizations.of(context)!.disclaimer,
                          style: const TextStyle(fontSize: 15,color: Color(0xFF4187FD)),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
            const SizedBox(height: 20),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                SizedBox(
                  width: 120,
                  height: 38,
                  child: OutlinedButton(
                    style: OutlinedButton.styleFrom(
                      side: const BorderSide(color: Color(0xFF5D5FEE)),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(19),
                      ),
                    ),
                    onPressed: () => onCancel(),
                    child: Text(
                      AppLocalizations.of(context)!.cancel,
                      style: const TextStyle(
                        color: Color(0xFF5D5FEE),
                        fontSize: 14,
                      ),
                    ),
                  ),
                ),
                SizedBox(
                  width: 120,
                  height: 38,
                  child: ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      backgroundColor: const Color(0xFF5D5FEE),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(19),
                      ),
                    ),
                    onPressed: () => onSure(),
                    child: Text(
                      AppLocalizations.of(context)!.confirm,
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 14,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}